function setCookie(name,value)
{
    var Days = 1;//过期时间
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

//读取cookies
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]);
    else
        return null;
} 
function delCookie( name, path, domain ) {    
	  if ( getCookie( name ) )   
		  document.cookie = name + '=' + ( ( path ) ? ';path=' + path : '') +( ( domain ) ? ';domain=' + domain : '' ) +  ';expires=Thu, 01-Jan-1970 00:00:01 GMT';     
} 
function $$(id){
	return document.getElementById(id);
}
// 鼠标放入输入框清空value
function OnEnter(field,type) { 
	if( field.value == field.defaultValue ) {
		if(type=='passwd') {
			if($(field).attr('type')=='text'){
				$(field).hide();
				$('#passwd').show();
				$('#passwd').focus()
			}
		}
		field.value = ""; 
	}
}  
function OnExit(field,type) { 
	if( field.value == "" ) {
		if($(field).attr('type')=='password'){
			$(field).hide();
			$('#passwdt').show();
			$('#passwdt').val('请输入密码');
		}else	field.value = field.defaultValue; 
	} 
}
function fleshVerify(name){ //重载验证码
	var timenow = new Date().getTime();
	$("#"+name).attr("src", '/public/verify/'+timenow);
}
//错误提示
function errorTip(id,errorInfo,color)
{
	if(color)errorInfo="<font color='"+color+"'>"+errorInfo+"</font>";
	$('#'+id).poshytip('update',  errorInfo); 
	$('#'+id).poshytip('show');
}
function msgTip(id,errorInfo,color)
{
	if(color)errorInfo="<font color='"+color+"'>"+errorInfo+"</font>";
	$('#'+id).poshytip('update',  errorInfo); 
	$('#'+id).poshytip('show');
}
function closeMsg(id)
{
	$('#'+id).poshytip('hide'); 	
}



//放上时 边框变颜色
function setFocusBorderColor(id)
{
    $("#"+id).css("border","1px solid #e77d00");
}

//放上时 边框变颜色
function setBlurBorderColor(id)
{
    $("#"+id).css("border","1px solid #DADADA");
}
/* 检查长度 */
function str_length(str){
	sl1=str.length;
	strLen=0;
	for(var i=0;i<sl1;i++){
		if(str.charCodeAt(i)>255) strLen+=3;
	 else strLen++;
	}
	return strLen;
}
/*****
 * 身份证号码检查
 * @param code
 * @returns 
 */
function IdentityCodeValid(code) { 
    var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
    var tip = "";
    var pass= true;
	var area,birthday;
	var card_id = code;
 if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(code))){
	tip = "身份证号格式不对";
	pass = false;
 }else  if(!city[code.substr(0,2)]){
        tip = "地址编码错误";
        pass = false;

  }else{
		if (code.length == 15)
	{
		re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
		var arrSplit = code.match(re);
		//检查生日日期是否正确
		var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
		var bGoodDay;
		bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
		birthday = '19' + arrSplit[2]+'-'+arrSplit[3]+'-'+arrSplit[4];
		if (!bGoodDay)
		{
			tip = "身份证号里出生日期不对！";
			pass = false;
		}/****
		else
		{
				//将15位身份证转成18位
				//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
				var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
				var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
				var nTemp = 0, i;
				code = code.substr(0, 6) + '19' + code.substr(6, code.length - 6);
				for(i = 0; i < 17; i ++)
				{
					nTemp += code.substr(i, 1) * arrInt[i];
				}
				code += arrCh[nTemp % 11];
				//return true;
		}***/
	}else if(code.length == 18){//18位身份证需要验证最后一位校验位
			var re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
			var arrSplit = code.match(re);
			var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
			var bGoodDay;
			 bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
			 birthday = arrSplit[2]+'-'+arrSplit[3]+'-'+arrSplit[4];
			 if (!bGoodDay)
			{
				tip = "身份证号里出生日期不对！";
				pass = false;
			}else{
				code = code.split('');
				//∑(ai×Wi)(mod 11)
				//加权因子
				var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
				//校验位
				var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
				var sum = 0;
				var ai = 0;
				var wi = 0;
				for (var i = 0; i < 17; i++)
				{
					ai = code[i];
					wi = factor[i];
					sum += ai * wi;
				}
				var last = parity[sum % 11];
				if(parity[sum % 11] != code[17]){
					tip = "校验位错误";
					pass =false;
				}
			}
        }
    }
    if(!pass){
		return {"status":false,"message":tip};
	}else{
		return {"status":true,"area":city[card_id.substr(0,2)],"birthday":birthday};
	}
}
 function RemainTime(){
    	var iDay,iHour,iMinute,iSecond;
    	var sDay="",sTime="";
    	    if (iTime >= 0){
    	        iDay = parseInt(iTime/24/3600);
    	        iHour = parseInt((iTime/3600)%24);
    	        iMinute = parseInt((iTime/60)%60);
    	        iSecond = parseInt(iTime%60);
    	  
    	   if (iDay > 0){ 
    	    sDay = iDay + "天"; 
    	   }
    	   sTime =sDay + iHour + "时" + iMinute + "分" + iSecond + "秒";
    	  
    	        if(iTime==0){
    	           clearTimeout(Account);
    	           sTime="<span style='color:green'>时间到了！</span>";
    	        }else{
    	           Account = setTimeout("RemainTime()",1000);
    	        }
    	        iTime=iTime-1;
    	    }else{
    	        sTime="<span style='color:red'>此标已过期！</span>";
				$('#account_but').attr("disabled","disabled");
				$('#account_but').val('此标已过期！');
				$("#account_but").css("background-color","#808080");
    	    }
    		document.getElementById(CID).innerHTML = sTime;
    	}
